package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.model.dao.LpOrderformTblMapper;
import cn.com.lsy.product.lepao.model.dao.LpZhimaAccreditCallBackTblMapper;
import cn.com.lsy.product.lepao.model.entities.LpOrderformTbl;
import cn.com.lsy.product.lepao.model.entities.LpZhimaAccreditCallBackTbl;
import cn.com.lsy.product.lepao.model.entities.LpZhimaAccreditCallBackTblExample;
import cn.com.lsy.product.lepao.model.mt.dao.MtGiveInfoMapper;
import cn.com.lsy.product.lepao.model.mt.dao.MtOrderFormMapper;
import cn.com.lsy.product.lepao.model.mt.entities.*;
import cn.com.lsy.product.lepao.service.IFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FinanceService implements IFinanceService {

    @Autowired
    MtOrderFormMapper mtOrderFormMapper;
    @Autowired
    MtGiveInfoMapper mtGiveInfoMapper;
    @Autowired
    LpOrderformTblMapper lpOrderformTblMapper;
    @Autowired
    LpZhimaAccreditCallBackTblMapper lpZhimaAccreditCallBackTblMapper;

    @Override
    public List<SearchDepositListDto> selectDepositByPage(int start, int end, String status, String startTime, String endTime, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("start", start);
        where.put("end", end);
        where.put("status", status);
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);

        return mtOrderFormMapper.selectDepositByPage(where);
    }

    @Override
    public int selectDepositByCount(String status, String startTime, String endTime, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("status", status);
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);

        return mtOrderFormMapper.selectDepositByCount(where);
    }

    @Override
    public List<IncomeListDto> selectIncomeByPage(int start, int end, String status, String startTime, String endTime, String searchCondition, List<Integer> storeIdList, int storeId, int goodsType) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("start", start);
        where.put("end", end);
        where.put("status", Integer.valueOf(status));
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);
        where.put("storeIdList", storeIdList);
        where.put("storeId", storeId);
        where.put("goodsType", goodsType);

        return mtOrderFormMapper.selectIncomeByPage(where);
    }

    @Override
    public int selectIncomeByCount(String status, String startTime, String endTime, String searchCondition, List<Integer> storeIdList, int storeId, int goodsType) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("status", Integer.valueOf(status));
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);
        where.put("storeIdList", storeIdList);
        where.put("storeId", storeId);
        where.put("goodsType", goodsType);

        return mtOrderFormMapper.selectIncomeByCount(where);
    }

    @Override
    public OrderPayInfoDto selectOrderPayInfo(int orderId) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("orderId", orderId);

        return mtOrderFormMapper.selectOrderPayInfo(where);
    }

    @Override
    public List<BalanceListDto> selectBalanceByPage(int start, int end, String startTime, String endTime, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("start", start);
        where.put("end", end);
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);

        return mtOrderFormMapper.selectBalanceByPage(where);

    }

    @Override
    public int selectBalanceByCount(String startTime, String endTime, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);

        return mtOrderFormMapper.selectBalanceByCount(where);

    }

    @Override
    public List<GiveListDto> selectGiveByPage(int start, int end, String startTime, String endTime, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("start", start);
        where.put("end", end);
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);

        return mtGiveInfoMapper.selectByPage(where);
    }

    @Override
    public int selectGiveByCount(String startTime, String endTime, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);

        return mtGiveInfoMapper.selectByCount(where);
    }

    @Override
    public LpOrderformTbl selectOrderInfo(int orderId) {

        return lpOrderformTblMapper.selectByPrimaryKey(orderId);
    }

    @Override
    public boolean updateOrder(LpOrderformTbl param) {

        if (lpOrderformTblMapper.updateByPrimaryKeySelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public BigDecimal selectIncomeSum(String status, String startTime, String endTime, String searchCondition, List<Integer> storeIdList, int storeId, int goodsType) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("status", status);
        where.put("startTime", startTime);
        where.put("endTime", endTime);
        where.put("searchCondition", searchCondition);
        where.put("storeIdList", storeIdList);
        where.put("storeId", storeId);
        where.put("goodsType", goodsType);

        return mtOrderFormMapper.selectIncomeSum(where);
    }

    @Override
    public BigDecimal selectDepositSum() {

        return mtOrderFormMapper.selectDepositSum();
    }

    @Override
    public List<LpZhimaAccreditCallBackTbl> selectZhimaAccreditCallBack(int ofId) {

        LpZhimaAccreditCallBackTblExample example = new LpZhimaAccreditCallBackTblExample();
        example.createCriteria().andOfIdEqualTo(ofId);

        return lpZhimaAccreditCallBackTblMapper.selectByExample(example);
    }

    @Override
    public int selectBuyCardTotal(int goodsType, String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("goodsType", goodsType);
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtOrderFormMapper.selectBuyCardTotal(where);
    }

    @Override
    public BigDecimal selectReachargeTotal(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtOrderFormMapper.selectReachargeTotal(where);
    }

    @Override
    public List<TodayStoreIncomeDto> selectTodayStoreIncome(String startTime, String endTime) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("startTime", startTime);
        where.put("endTime", endTime);

        return mtOrderFormMapper.selectTodayStoreIncome(where);
    }

}
